package cn.mxb.logic.dao;

import java.util.List;

import org.springframework.stereotype.Repository;

import cn.mxb.floor.dao.impl.BaseDaoImpl;
import cn.mxb.floor.pagination.Result;
import cn.mxb.logic.entity.SysRole;

@Repository("sysRoleDAO")
public class SysRoleDAO  extends BaseDaoImpl<SysRole>   {

	/**
	 * 分页
	 * @return_type: Result<SysRole>
	 */
	@SuppressWarnings("unchecked")
	public Result<SysRole> find(SysRole sysRole, int page, int size){
		String queryString = "from SysRole where 1=1";
		if(sysRole.getRoleId() !=null && !"".equals(sysRole.getRoleId())){
			queryString = queryString + " and roleId = '"+sysRole.getRoleId()+"' ";
		}
		int start=(page-1)*size;
		int limit =size;
		String msg = "";
		return (Result<SysRole>)super.find(queryString, null, null, start, limit,msg);
	}
	
	/**
	 * 根据字段property的值value查询
	 */
	@SuppressWarnings("unchecked")
	public List<SysRole> findListByProperty(String property,String value){
		List<SysRole> list = null;
		String queryString = "from SysRole where "+property+" like '%"+value+"%'";
		
		try{
		   list = this.getHibernateTemplate().find(queryString);
		}catch(Exception e){
			System.out.println(e);
		}
		return list;
	}
	
	/**
	 * 
	 * 根据字段值查询(实体)
	 */
	@SuppressWarnings("unchecked")
	public SysRole findByProperty(String property, String value) {
		List<SysRole> list = null;
		SysRole sysRole = null;
		String queryString = "from SysRole where "+property+" like '%"+value+"%'";
		try{
		   list = this.getHibernateTemplate().find(queryString);
		   if(list.size()>0 && list !=null){
			   sysRole = list.get(0);
		   }else{
			   System.out.println("SysRole kong");
		   }
		}catch(Exception e){
			System.out.println(e);
		}
		return sysRole;
	}
	
}
